package cn.edu.scau.cmi.liangzijian.interProgramming;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextArea;
import javafx.scene.input.MouseEvent;


public class UIController {

    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private TextArea board;

    @FXML
    private ComboBox<String> studentType;

    private String studentTypeString = null;

    private Student student;
    
    @FXML
    void act(MouseEvent event) {
    	if(studentTypeString.equals("undergraduateStudent")) {
    		student = new UndergraduateStudent();
    	} else {
    		student = new GraduateStudent();
    	}
		board.appendText(student.learning()+"\n");
    }

    @FXML
    void initialize() {
        assert board != null : "fx:id=\"board\" was not injected: check your FXML file 'UI.fxml'.";
        assert studentType != null : "fx:id=\"studentType\" was not injected: check your FXML file 'UI.fxml'.";

        studentType.setItems(FXCollections.observableArrayList("undergraduateStudent", "graduateStudent"));
        studentType.valueProperty().addListener(new ChangeListener() {
			@Override
			public void changed(ObservableValue observable, Object oldValue, Object newValue) {
				studentTypeString = (String)newValue;
			}    	
    	});
    }

}
